#!/usr/bin/env python
"""
# -*- coding: utf-8 -*-
# @Time    : 2020/9/18 17:10
# @Author  : AshJo
# @Desc    : 面向对象编程2
# @Filename: obj_program2.py
# @Version : v1.0
"""


# 在类中定义方法和调用方法


# 模拟人狗大战，回合制游戏

class Person:  # 人类
    def __init__(self, name, sex, job, hp, weapon, ad):
        """
        必须叫__init__这个名字，不能改变的，所有的在一个具体的人物出现之后拥有的属性,
        都可以写在这里
        """
        self.name = name
        self.sex = sex
        self.job = job
        self.level = 0
        self.hp = hp
        self.weapon = weapon
        self.ad = ad

    def hit(self, dog):
        print('--->dadada!')
        if dog.hp >= self.ad:
            dog.hp -= self.ad
        else:
            dog.hp = 0
        print('%s打%s,%s掉了%s点血' % (self.name, dog.name, dog.name, self.ad))
        print('*** %s当前剩余血量：%s ***' % (dog.name, dog.hp))


class Dog:  # 狗类
    def __init__(self, name, type, hp, ad):
        self.name = name
        self.type = type
        self.hp = hp
        self.ad = ad

    def bite(self, person):
        print('--->kakaka!')
        if person.hp >= self.ad:
            person.hp -= self.ad
        else:
            person.hp = 0
        print('%s咬%s,%s掉了%s点血' % (self.name, person.name, person.name, self.ad))
        print('*** %s当前剩余血量：%s ***' % (person.name, person.hp))


cleverlove = Person('明凯', '男', '打野', 4396, '养猪', 996)
husky = Dog('cindy', '哈士奇', 4396, 998)

count = 1  # 控制回合
for i in range(100):
    if count % 2 == 1:
        print(f'++++++++++回合{count}:++++++++++')
        if cleverlove.hp > 0 and husky.hp > 0:
            cleverlove.hit(husky)
            count += 1
            if husky.hp == 0:
                print('%s 胜利！游戏结束！' % cleverlove.name)
                break
    elif count % 2 == 0:
        print(f'++++++++++回合{count}:++++++++++')
        if husky.hp > 0 and cleverlove.hp > 0:
            husky.bite(cleverlove)
            count += 1
            if cleverlove.hp == 0:
                print('%s 胜利！游戏结束！' % husky.name)
                break
